package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.AccidentRegister;
import com.ruibang.glass.equipment.service.AccidentRegisterService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 *事故台账接口服务
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */

@RestController
@RequestMapping("/api/equipment/accident/register")
@Api(value = "事故台账")
public class AccidentRegisterController {
    @Autowired
    private AccidentRegisterService accidentRegisterService;

    @PostMapping("list")
    @ApiOperation(value = "事故台账列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageReq) {
        return ResultBody.success(accidentRegisterService.queryPage(deviceAllPageReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody AccidentRegister accidentRegister) {
        return ResultBody.success(accidentRegisterService.updateOrAddById(accidentRegister));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody AccidentRegister accidentRegister) {
        if (CollectionUtils.isNotEmpty(accidentRegister.getIds())) {
//            accidentRegisterService.removeBatchByIds(accidentRegister.getIds());
            accidentRegisterService.lambdaUpdate().set(AccidentRegister::getIsDelete, Constants.ONE_STR).in(AccidentRegister::getId,accidentRegister.getIds()).update();

        }
        if (StringUtils.isNoneBlank(accidentRegister.getId())) {
//            accidentRegisterService.removeById(accidentRegister.getId());
            accidentRegisterService.lambdaUpdate().set(AccidentRegister::getIsDelete, Constants.ONE_STR).eq(AccidentRegister::getId,accidentRegister.getId()).update();
        }
        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "获取对象", response = ResultBody.class)
    public ResultBody getOne(@RequestBody AccidentRegister accidentRegister) {
        return ResultBody.success(accidentRegisterService.getDetail(accidentRegister.getId()));
    }


    @GetMapping("download/{id}")
    @ApiOperation(value = "下载", response = ResultBody.class)
    public void download(@PathVariable("id") String id) {
        accidentRegisterService.download(id);
    }


}
